package com.ibm.util;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.ibm.interfaces.ITimeSeriesSchema;
import com.ibm.util.exception.CPSException;


/**
 * Load the schema into memory
 * 
 * @author Yaoliang
 *
 */
public abstract class SchemaCache {
	protected HashMap<String, ITimeSeriesSchema> schemaMap;
	protected HashMap<String, String> schematypeMap;
	
	static private SchemaCache _inst;
	protected static Logger logger = Logger.getLogger(SchemaCache.class);
	
	static public SchemaCache getInstace() {
		if (_inst == null)
			_inst = new PreLoadingSchemaCache();

		return _inst;
	}
	
	SchemaCache() {
		logger.info("Loading schema cache instance .. ");
		this.schemaMap = new HashMap<String, ITimeSeriesSchema>();
		this.schematypeMap = new HashMap<String,String>();
	}

	
	public void flushKey(String schemaid) {
		schemaMap.remove(schemaid);
		schematypeMap.remove(schemaid);
	}
	
	public abstract ITimeSeriesSchema getSchema(String tenantid, String schemaid,ArrayList<String> type) throws CPSException;
}
